package com.yunxi.controller.sys;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.sys.pojo.RoleMenuVO;
import com.yunxi.sys.service.RoleMenuDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;

/**
 * Created by wangxinxin on 2018/10/20.
 */
@RestController
@RequestMapping("/admin/roleMenu")
@Api(tags = "sys:rolemenu", description = "角色菜单接口")
public class RoleMenuController {
    private static final Logger logger = LoggerFactory.getLogger(RoleMenuController.class);
    @Autowired
    RoleMenuDubboService roleMenuDubboService;
    /**
     * 查询角色菜单列表
     * @param params
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询角色菜单列表")
    public Object list(@RequestParam Map<String,String> params) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
        Object o = roleMenuDubboService.listByRoleId(params.get("id"));
        return o;
    }

    /**
     *保存角色菜单
     * @return
     * @throws Exception
     */
    @PostMapping("/save")
    @ApiOperation(value = "保存角色菜单")
    public ApiResult save(@RequestBody RoleMenuVO roleMenu, @CurrentUser LoginInfo user) throws Exception{
        roleMenuDubboService.saveRoleMenuList(roleMenu,user.getUserId());
        return ResponseUtil.ok("success");
    }
}
